package action.chap6;

import action.chap4.Dish;
import action.chap4.DishUtils;

import java.util.List;
import java.util.Map;
import java.util.function.Function;

import static java.util.stream.Collectors.groupingBy;


public class Demo63 {
    public static void main(String[] args) {
        List<Dish> menus = DishUtils.getListDish();
        Map<Object, List<Dish>> collect = menus.stream().collect(groupingBy((Function<Dish, Object>) Dish::getType));
        System.out.println(collect);
        Map<CaloricLevel, List<Dish>> collect1 = menus.stream().collect(groupingBy(dish -> {
            if (dish.getCalories() <= 400) return CaloricLevel.DIET;
            else if (dish.getCalories() <= 700) return
                    CaloricLevel.NORMAL;
            else return CaloricLevel.FAT;
        }));
        // 多级分组
        Map<Dish.Type, Map<CaloricLevel, List<Dish>>> collect2 = menus.stream().collect(groupingBy(Dish::getType, groupingBy(dish -> {
            if (dish.getCalories() <= 400) return CaloricLevel.DIET;
            else if (dish.getCalories() <= 700) return
                    CaloricLevel.NORMAL;
            else return CaloricLevel.FAT;
        })));
    }

    public enum CaloricLevel {DIET, NORMAL, FAT}


}
